@@ -21,7 +21,7 @@ module Agents |
||
21 | 21 |
message => "Today's conditions look like <$.conditions> and high temperaure is going to be <$.high.celsius> degree Celsius."" |
22 | 22 |
subject => "$.data" |
23 | 23 |
|
24 |
- JSONPaths must be between < and > . Make sure you dont use these symbols anywhere else. You can add as many keys as you like. |
|
24 |
+ JSONPaths must be between < and > . Make sure you dont use these symbols anywhere else. |
|
25 | 25 |
|
26 | 26 |
Event generated by Event Formatting Agent will be like |
27 | 27 |
|
@@ -78,7 +78,6 @@ module Agents |
||
78 | 78 |
end |
79 | 79 |
|
80 | 80 |
def receive_webhook(params) |
81 |
- create_event :payload => params |
|
82 | 81 |
if memory[:pending_calls].has_key? params[:secret].to_sym |
83 | 82 |
response = Twilio::TwiML::Response.new {|r| r.Say memory[:pending_calls][params[:secret].to_sym], :voice => 'woman'} |
84 | 83 |
memory[:pending_calls].delete params[:secret].to_sym |
@@ -0,0 +1 @@ |
||
1 |
+.DS_Store |
@@ -0,0 +1,10 @@ |
||
1 |
+#!/usr/bin/env ruby |
|
2 |
+#^syntax detection |
|
3 |
+ |
|
4 |
+site 'http://community.opscode.com/api/v1' |
|
5 |
+ |
|
6 |
+cookbook 'runit' |
|
7 |
+cookbook 'git', :git => 'git://github.com/opscode-cookbooks/git.git' |
|
8 |
+cookbook 'nginx', :git => 'git://github.com/opscode-cookbooks/nginx.git' |
|
9 |
+cookbook 'mysql', :git => 'git://github.com/opscode-cookbooks/mysql.git' |
|
10 |
+cookbook 'nodejs', :git => 'git://github.com/mdxp/nodejs-cookbook.git' |
@@ -0,0 +1,45 @@ |
||
1 |
+Install librarian-chef gem |
|
2 |
+ |
|
3 |
+ gem install librarian-chef |
|
4 |
+ |
|
5 |
+And Vagrant plugins |
|
6 |
+ |
|
7 |
+ vagrant plugin install vagrant-aws |
|
8 |
+ vagrant plugin install vagrant-omnibus |
|
9 |
+ |
|
10 |
+Move to repo directory and run |
|
11 |
+ |
|
12 |
+ librarian-chef install |
|
13 |
+ |
|
14 |
+This will install all the cookbooks mentioned in Cheffile. |
|
15 |
+ |
|
16 |
+To install Huginn on AWS, fill the Vagrantfile with your account details and run |
|
17 |
+ |
|
18 |
+ vagrant up ec2 --provider=aws |
|
19 |
+ |
|
20 |
+To install it on a virtualbox VM: |
|
21 |
+ |
|
22 |
+ vagrant up vb |
|
23 |
+ |
|
24 |
+It'll install huginn and get the server started. You can now go to `yourserver.com/3000` to use huginn if you are in virtualbox. On ec2, pointing to public DNS will let you access huginn. Huginn will be at `/home/huginn/huginn`. A new dedicated user will be created for managing huginn with username `huginn` and password `huginn`. To ssh into ec2: |
|
25 |
+ |
|
26 |
+ vagrant ssh ec2 |
|
27 |
+ |
|
28 |
+Similarly, to ssh into VirtualBox |
|
29 |
+ |
|
30 |
+ vagrant ssh vb |
|
31 |
+ |
|
32 |
+After ssh-ing into ec2, you can start(its already running), stop or restart huginn by |
|
33 |
+ |
|
34 |
+ sudo start huginn |
|
35 |
+ sudo stop huginn |
|
36 |
+ sudo restart huginn |
|
37 |
+ |
|
38 |
+To terminate ec2 instance: |
|
39 |
+ |
|
40 |
+ vagrant destroy ec2 |
|
41 |
+ |
|
42 |
+Similarly, to destroy VirtualBox VM |
|
43 |
+ |
|
44 |
+ vagrant destroy vb |
|
45 |
+ |
@@ -0,0 +1,63 @@ |
||
1 |
+# -*- mode: ruby -*- |
|
2 |
+# vi: set ft=ruby : |
|
3 |
+ |
|
4 |
+Vagrant.configure("2") do |config| |
|
5 |
+ # Every Vagrant virtual environment requires a box to build off of. |
|
6 |
+ config.omnibus.chef_version = :latest |
|
7 |
+ config.vm.define :vb do |vb| |
|
8 |
+ # vagrant up vb |
|
9 |
+ vb.vm.box = "precise32" |
|
10 |
+ vb.vm.box_url = "http://files.vagrantup.com/precise32.box" |
|
11 |
+ vb.vm.network :forwarded_port, host: 3000, guest: 3000 |
|
12 |
+ |
|
13 |
+ vb.vm.provision :chef_solo do |chef| |
|
14 |
+ chef.roles_path = "roles" |
|
15 |
+ chef.cookbooks_path = ["cookbooks", "site-cookbooks"] |
|
16 |
+ chef.add_role("huginn_development") |
|
17 |
+ chef.json = { |
|
18 |
+ "mysql"=> { |
|
19 |
+ "server_root_password" => "", |
|
20 |
+ "server_repl_password" => "", |
|
21 |
+ "server_debian_password"=> "" |
|
22 |
+ }, |
|
23 |
+ "nginx" => { |
|
24 |
+ 'init_style' => "upstart" |
|
25 |
+ } |
|
26 |
+ } |
|
27 |
+ end |
|
28 |
+ end |
|
29 |
+ |
|
30 |
+ config.vm.define :ec2 do |ec2| |
|
31 |
+ # vagrant plugin install vagrant-aws |
|
32 |
+ # vagrant plugin install vagrant-omnibus -- So as to make sure chef is installed on ec2 instance |
|
33 |
+ # vagrant up ec2 --provider=aws |
|
34 |
+ ec2.vm.box = "dummy" |
|
35 |
+ ec2.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box" |
|
36 |
+ |
|
37 |
+ ec2.vm.provider :aws do |aws, override| |
|
38 |
+ aws.access_key_id = "" |
|
39 |
+ aws.secret_access_key = "" |
|
40 |
+ aws.keypair_name = "" |
|
41 |
+ aws.region = "us-east-1" |
|
42 |
+ aws.ami = "ami-d0f89fb9" |
|
43 |
+ |
|
44 |
+ override.ssh.username = "ubuntu" |
|
45 |
+ override.ssh.private_key_path = "" |
|
46 |
+ end |
|
47 |
+ ec2.vm.provision :chef_solo do |chef| |
|
48 |
+ chef.roles_path = "roles" |
|
49 |
+ chef.cookbooks_path = ["cookbooks", "site-cookbooks"] |
|
50 |
+ chef.add_role("huginn_production") |
|
51 |
+ chef.json = { |
|
52 |
+ "mysql"=> { |
|
53 |
+ "server_root_password" => "", |
|
54 |
+ "server_repl_password" => "", |
|
55 |
+ "server_debian_password"=> "" |
|
56 |
+ }, |
|
57 |
+ "nginx" => { |
|
58 |
+ 'init_style' => "upstart" |
|
59 |
+ } |
|
60 |
+ } |
|
61 |
+ end |
|
62 |
+ end |
|
63 |
+end |
@@ -0,0 +1,18 @@ |
||
1 |
+{ |
|
2 |
+ |
|
3 |
+"name" : "huginn_development", |
|
4 |
+ |
|
5 |
+"chef_type" : "role", |
|
6 |
+ |
|
7 |
+"json_class" : "Chef::Role", |
|
8 |
+ |
|
9 |
+"description" : "Huginn Development Environment", |
|
10 |
+ |
|
11 |
+"run_list":[ |
|
12 |
+ "recipe[git]", |
|
13 |
+ "recipe[apt]", |
|
14 |
+ "recipe[mysql::server]", |
|
15 |
+ "recipe[nodejs::install_from_binary]", |
|
16 |
+ "recipe[huginn_development]" |
|
17 |
+ ] |
|
18 |
+} |
@@ -0,0 +1,19 @@ |
||
1 |
+{ |
|
2 |
+ |
|
3 |
+"name" : "huginn_production", |
|
4 |
+ |
|
5 |
+"chef_type" : "role", |
|
6 |
+ |
|
7 |
+"json_class" : "Chef::Role", |
|
8 |
+ |
|
9 |
+"description" : "Huginn Production Environment", |
|
10 |
+ |
|
11 |
+"run_list":[ |
|
12 |
+ "recipe[git]", |
|
13 |
+ "recipe[apt]", |
|
14 |
+ "recipe[mysql::server]", |
|
15 |
+ "recipe[nodejs::install_from_binary]", |
|
16 |
+ "recipe[nginx]", |
|
17 |
+ "recipe[huginn_production]" |
|
18 |
+ ] |
|
19 |
+} |
@@ -0,0 +1,44 @@ |
||
1 |
+include_recipe 'apt' |
|
2 |
+include_recipe 'build-essential' |
|
3 |
+ |
|
4 |
+%w("ruby1.9.1" "ruby1.9.1-dev" "libxslt-dev" "libxml2-dev" "curl").each do |pkg| |
|
5 |
+ package pkg do |
|
6 |
+ action :install |
|
7 |
+ end |
|
8 |
+end |
|
9 |
+ |
|
10 |
+git "/usr/local/huginn" do |
|
11 |
+ repository 'git://github.com/cantino/huginn.git' |
|
12 |
+ reference 'master' |
|
13 |
+ action :sync |
|
14 |
+end |
|
15 |
+ |
|
16 |
+gem_package("rake") |
|
17 |
+gem_package("bundle") |
|
18 |
+ |
|
19 |
+bash "huginn dependencies" do |
|
20 |
+ user "root" |
|
21 |
+ cwd "/usr/local/huginn" |
|
22 |
+ code <<-EOH |
|
23 |
+ export LANG="en_US.UTF-8" |
|
24 |
+ export LC_ALL="en_US.UTF-8" |
|
25 |
+ bundle install |
|
26 |
+ sed s/REPLACE_ME_NOW\!/$(rake secret)/ .env.example > .env |
|
27 |
+ rake db:create |
|
28 |
+ rake db:migrate |
|
29 |
+ rake db:seed |
|
30 |
+ EOH |
|
31 |
+end |
|
32 |
+ |
|
33 |
+#log "huginn start" do |
|
34 |
+# level :info |
|
35 |
+# message "Huginn has been installed and wil start at your instance in two minutes" |
|
36 |
+#end |
|
37 |
+ |
|
38 |
+bash "Huginn has been installed and server will start in a minute" do |
|
39 |
+ user "root" |
|
40 |
+ cwd "/usr/local/huginn" |
|
41 |
+ code <<-EOH |
|
42 |
+ sudo foreman start |
|
43 |
+ EOH |
|
44 |
+end |
@@ -0,0 +1,59 @@ |
||
1 |
+source 'https://rubygems.org' |
|
2 |
+ |
|
3 |
+gem 'rails' |
|
4 |
+gem 'rake' |
|
5 |
+gem 'mysql2' |
|
6 |
+gem 'devise' |
|
7 |
+gem 'rails_admin' |
|
8 |
+gem 'kaminari' |
|
9 |
+gem 'bootstrap-kaminari-views' |
|
10 |
+gem "rufus-scheduler", :require => false |
|
11 |
+gem 'json', '>= 1.7.7' |
|
12 |
+gem 'jsonpath' |
|
13 |
+gem 'twilio-ruby' |
|
14 |
+ |
|
15 |
+gem 'delayed_job', :git => 'https://github.com/wok/delayed_job' # Until the YAML issues are fixed in master. |
|
16 |
+gem 'delayed_job_active_record', "~> 0.3.3" # newer was giving a strange MySQL error |
|
17 |
+gem "daemons" |
|
18 |
+# gem "delayed_job_web" |
|
19 |
+group :production do |
|
20 |
+ gem 'unicorn' |
|
21 |
+end |
|
22 |
+gem 'foreman' |
|
23 |
+gem 'dotenv-rails', :groups => [:development, :test] |
|
24 |
+ |
|
25 |
+group :assets do |
|
26 |
+ gem 'sass-rails', '~> 3.2.3' |
|
27 |
+ gem 'coffee-rails', '~> 3.2.1' |
|
28 |
+ gem 'uglifier', '>= 1.0.3' |
|
29 |
+ gem 'select2-rails' |
|
30 |
+ gem 'jquery-rails' |
|
31 |
+end |
|
32 |
+ |
|
33 |
+gem 'geokit-rails3' |
|
34 |
+gem 'kramdown' |
|
35 |
+gem "typhoeus" |
|
36 |
+gem 'nokogiri' |
|
37 |
+gem 'wunderground' |
|
38 |
+ |
|
39 |
+gem "twitter" |
|
40 |
+gem 'twitter-stream', '>=0.1.16' |
|
41 |
+gem 'em-http-request' |
|
42 |
+ |
|
43 |
+platforms :ruby_18 do |
|
44 |
+ gem 'system_timer' |
|
45 |
+ gem 'fastercsv' |
|
46 |
+end |
|
47 |
+ |
|
48 |
+group :development do |
|
49 |
+ gem 'pry' |
|
50 |
+end |
|
51 |
+ |
|
52 |
+group :development, :test do |
|
53 |
+ gem 'rspec-rails' |
|
54 |
+ gem 'rspec' |
|
55 |
+ gem 'shoulda-matchers' |
|
56 |
+ gem 'rr' |
|
57 |
+ gem 'webmock', :require => false |
|
58 |
+ gem 'rake' |
|
59 |
+end |
@@ -0,0 +1,4 @@ |
||
1 |
+web: sudo bundle exec unicorn_rails -c config/unicorn.rb |
|
2 |
+schedule: sudo bundle exec rails runner bin/schedule.rb |
|
3 |
+twitter: sudo bundle exec rails runner bin/twitter_stream.rb |
|
4 |
+dj: sudo bundle exec script/delayed_job run |
@@ -0,0 +1,37 @@ |
||
1 |
+#worker_process 2; |
|
2 |
+#user huginn huginn; |
|
3 |
+ |
|
4 |
+events { |
|
5 |
+ worker_connections 1024; |
|
6 |
+ accept_mutex on; |
|
7 |
+} |
|
8 |
+ |
|
9 |
+http { |
|
10 |
+ upstream huginn_server { |
|
11 |
+ server unix:/home/huginn/huginn/tmp/sockets/unicorn.sock; |
|
12 |
+} |
|
13 |
+ |
|
14 |
+ server { |
|
15 |
+ listen 80; |
|
16 |
+ server_name _; |
|
17 |
+ keepalive_timeout 5; |
|
18 |
+ root /home/huginn/huginn/public; |
|
19 |
+ try_files $uri/index.html $uri.html $uri @app; |
|
20 |
+ error_page 500 502 503 504 /500.html; |
|
21 |
+ location = /500.html { |
|
22 |
+ root /home/huginn/huginn/public; |
|
23 |
+ } |
|
24 |
+ location @app { |
|
25 |
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
26 |
+ |
|
27 |
+ proxy_set_header X-Forwarded-Proto $scheme; |
|
28 |
+ |
|
29 |
+ proxy_set_header Host $http_host; |
|
30 |
+ |
|
31 |
+ proxy_redirect off; |
|
32 |
+ |
|
33 |
+ proxy_pass http://huginn_server; |
|
34 |
+ } |
|
35 |
+} |
|
36 |
+} |
|
37 |
+ |
@@ -0,0 +1,33 @@ |
||
1 |
+app_path = "/home/huginn/huginn" |
|
2 |
+ |
|
3 |
+worker_processes 2 |
|
4 |
+preload_app true |
|
5 |
+timeout 180 |
|
6 |
+listen '/home/huginn/huginn/tmp/sockets/unicorn.sock' |
|
7 |
+ |
|
8 |
+working_directory app_path |
|
9 |
+ |
|
10 |
+rails_env = ENV['RAILS_ENV'] || 'production' |
|
11 |
+ |
|
12 |
+# Log everything to one file |
|
13 |
+stderr_path "log/unicorn_out.log" |
|
14 |
+stdout_path "log/unicorn_err.log" |
|
15 |
+ |
|
16 |
+# Set master PID location |
|
17 |
+pid '/home/huginn/huginn/tmp/pids/unicorn.pid' |
|
18 |
+ |
|
19 |
+before_fork do |server, worker| |
|
20 |
+ ActiveRecord::Base.connection.disconnect! |
|
21 |
+ old_pid = "#{server.config[:pid]}.oldbin" |
|
22 |
+ if File.exists?(old_pid) && server.pid != old_pid |
|
23 |
+ begin |
|
24 |
+ Process.kill("QUIT", File.read(old_pid).to_i) |
|
25 |
+ rescue Errno::ENOENT, Errno::ESRCH |
|
26 |
+ # someone else did our job for us |
|
27 |
+ end |
|
28 |
+ end |
|
29 |
+end |
|
30 |
+ |
|
31 |
+after_fork do |server, worker| |
|
32 |
+ ActiveRecord::Base.establish_connection |
|
33 |
+end |
@@ -0,0 +1,101 @@ |
||
1 |
+include_recipe 'apt' |
|
2 |
+include_recipe 'build-essential' |
|
3 |
+ |
|
4 |
+user "huginn" do |
|
5 |
+ action :create |
|
6 |
+ system true |
|
7 |
+ home "/home/huginn" |
|
8 |
+ password "$6$ZwO6b.6tij$SMa8UIwtESGDxB37NwHsct.gJfXWmmflNbH.oypwJ9y0KkzMkCdw7D14iK7GX9C4CWSEcpGOFUow7p01rQFu5." |
|
9 |
+ supports :manage_home => true |
|
10 |
+ shell "/bin/bash" |
|
11 |
+ gid "sudo" |
|
12 |
+end |
|
13 |
+ |
|
14 |
+group "huginn" do |
|
15 |
+ members ["huginn"] |
|
16 |
+ action :create |
|
17 |
+end |
|
18 |
+ |
|
19 |
+%w("ruby1.9.1" "ruby1.9.1-dev" "libxslt-dev" "libxml2-dev" "curl" "libshadow-ruby1.8").each do |pkg| |
|
20 |
+ package pkg do |
|
21 |
+ action :install |
|
22 |
+ end |
|
23 |
+end |
|
24 |
+ |
|
25 |
+git "/home/huginn/huginn" do |
|
26 |
+ repository 'git://github.com/cantino/huginn.git' |
|
27 |
+ reference 'master' |
|
28 |
+ action :sync |
|
29 |
+ user "huginn" |
|
30 |
+end |
|
31 |
+ |
|
32 |
+gem_package("rake") |
|
33 |
+gem_package("bundle") |
|
34 |
+ |
|
35 |
+cookbook_file "/etc/nginx/nginx.conf" do |
|
36 |
+ source "nginx.conf" |
|
37 |
+ owner "huginn" |
|
38 |
+end |
|
39 |
+ |
|
40 |
+directory "/home/huginn/huginn/tmp" do |
|
41 |
+ action :create |
|
42 |
+ owner "huginn" |
|
43 |
+ recursive true |
|
44 |
+end |
|
45 |
+ |
|
46 |
+directory "/home/huginn/huginn/log" do |
|
47 |
+ action :create |
|
48 |
+ owner "huginn" |
|
49 |
+ recursive true |
|
50 |
+end |
|
51 |
+ |
|
52 |
+cookbook_file "/home/huginn/huginn/config/unicorn.rb" do |
|
53 |
+ source "unicorn.rb" |
|
54 |
+ mode "644" |
|
55 |
+ owner "huginn" |
|
56 |
+end |
|
57 |
+ |
|
58 |
+cookbook_file "home/huginn/huginn/Gemfile" do |
|
59 |
+ source "Gemfile" |
|
60 |
+ mode "644" |
|
61 |
+ owner "huginn" |
|
62 |
+end |
|
63 |
+ |
|
64 |
+cookbook_file "home/huginn/huginn/.env" do |
|
65 |
+ source ".env" |
|
66 |
+ mode "666" |
|
67 |
+ owner "huginn" |
|
68 |
+end |
|
69 |
+ |
|
70 |
+cookbook_file "home/huginn/huginn/Procfile" do |
|
71 |
+ source "Procfile" |
|
72 |
+ mode "444" |
|
73 |
+ owner "huginn" |
|
74 |
+end |
|
75 |
+ |
|
76 |
+service "nginx" do |
|
77 |
+ action :start |
|
78 |
+end |
|
79 |
+ |
|
80 |
+bash "Setting huginn user with NOPASSWD option" do |
|
81 |
+ cwd "/etc/sudoers.d" |
|
82 |
+ code <<-EOH |
|
83 |
+ echo 'huginn ALL=(ALL) NOPASSWD:ALL' >> 90-cloudimg-ubuntu |
|
84 |
+ EOH |
|
85 |
+end |
|
86 |
+ |
|
87 |
+bash "huginn dependencies" do |
|
88 |
+ cwd "/home/huginn/huginn" |
|
89 |
+ user "huginn" |
|
90 |
+ code <<-EOH |
|
91 |
+ export LANG="en_US.UTF-8" |
|
92 |
+ export LC_ALL="en_US.UTF-8" |
|
93 |
+ sudo bundle install |
|
94 |
+ sed -i s/REPLACE_ME_NOW\!/$(sudo rake secret)/ .env |
|
95 |
+ sudo rake db:create |
|
96 |
+ sudo rake db:migrate |
|
97 |
+ sudo rake db:seed |
|
98 |
+ sudo foreman export upstart /etc/init -a huginn -u huginn |
|
99 |
+ sudo start huginn |
|
100 |
+ EOH |
|
101 |
+end |